package com.tiger.qcu.controller;

import java.util.List;
import java.util.Date;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tiger.common.annotation.Log;
import com.tiger.common.core.controller.BaseController;
import com.tiger.common.core.domain.AjaxResult;
import com.tiger.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import com.tiger.qcu.domain.NewsInfo;
import com.tiger.qcu.service.INewsInfoService;
import com.tiger.common.utils.poi.ExcelUtil;
import com.tiger.common.core.page.TableDataInfo;

import javax.validation.Valid;
import javax.validation.constraints.*;

/**
 * 新闻信息Controller
 * 
 * @author jerry
 * @date 2025-07-07
 */
@RestController
@RequestMapping("/newsInfo/newsInfo")
@Api(tags = " newsInfo管理")
public class NewsInfoController extends BaseController
{
    @Autowired
    private INewsInfoService newsInfoService;

    /**
     * 查询新闻信息列表
     */
    @PreAuthorize("@ss.hasPermi('newsInfo:newsInfo:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询新闻信息列表",notes = "新闻信息列表查询")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "newsId", value = "序号", dataType = "Long", dataTypeClass = Long.class),
        @ApiImplicitParam(name = "newsTitle", value = "新闻标题", dataType = "String", dataTypeClass = String.class),
        @ApiImplicitParam(name = "newsTime", value = "新闻发布时间", dataType = "Date", dataTypeClass = Date.class),
        @ApiImplicitParam(name = "newsContent", value = "新闻内容", dataType = "String", dataTypeClass = String.class),
        @ApiImplicitParam(name = "newsAbstract", value = "新闻摘要", dataType = "String", dataTypeClass = String.class),
        @ApiImplicitParam(name = "newsImg", value = "新闻图片", dataType = "String", dataTypeClass = String.class),
        @ApiImplicitParam(name = "userId", value = "用户ID", dataType = "Long", dataTypeClass = Long.class),
        @ApiImplicitParam(name = "deptId", value = "部门ID", dataType = "Long", dataTypeClass = Long.class),
        @ApiImplicitParam(name = "createBy", value = "创建者", dataType = "String", dataTypeClass = String.class),
        @ApiImplicitParam(name = "createTime", value = "创建时间", dataType = "Date", dataTypeClass = Date.class),
        @ApiImplicitParam(name = "updateBy", value = "更新者", dataType = "String", dataTypeClass = String.class),
        @ApiImplicitParam(name = "updateTime", value = "更新时间", dataType = "Date", dataTypeClass = Date.class),
        @ApiImplicitParam(name = "remark", value = "备注", dataType = "String", dataTypeClass = String.class),
    })

    public TableDataInfo list(NewsInfo newsInfo)
    {
        startPage();
        List<NewsInfo> list = newsInfoService.selectNewsInfoList(newsInfo);
        return getDataTable(list);
    }

    /**
     * 导出新闻信息列表
     */
    @PreAuthorize("@ss.hasPermi('newsInfo:newsInfo:export')")
    @Log(title = "新闻信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出新闻信息列表",notes = "导出新闻信息列表")
    public void export(HttpServletResponse response, NewsInfo newsInfo)
    {
        List<NewsInfo> list = newsInfoService.selectNewsInfoList(newsInfo);
        ExcelUtil<NewsInfo> util = new ExcelUtil<NewsInfo>(NewsInfo.class);
        util.exportExcel(response, list, "新闻信息数据");
    }

    /**
     * 获取新闻信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('newsInfo:newsInfo:query')")
    @GetMapping(value = "/{newsId}")
    @ApiOperation(value = "获取新闻信息详细信息",notes = "获取新闻信息详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "$column.javaField", value = "$column.columnComment", dataType = "newsId", dataTypeClass = Long.class),
    })
    public AjaxResult getInfo(@Valid @NotNull(message = "newsId不能为空") @PathVariable("newsId") Long newsId)
    {
        return success(newsInfoService.selectNewsInfoByNewsId(newsId));
    }

    /**
     * 新增新闻信息
     */
    @PreAuthorize("@ss.hasPermi('newsInfo:newsInfo:add')")
    @Log(title = "新闻信息", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增新闻信息",notes = "新增新闻信息")
    @ApiImplicitParams({
                @ApiImplicitParam(name = "newsId", value = "序号", dataType = "Long", dataTypeClass = Long.class),
                @ApiImplicitParam(name = "newsTitle", value = "新闻标题", dataType = "String", dataTypeClass = String.class),
                @ApiImplicitParam(name = "newsTime", value = "新闻发布时间", dataType = "Date", dataTypeClass = Date.class),
                @ApiImplicitParam(name = "newsContent", value = "新闻内容", dataType = "String", dataTypeClass = String.class),
                @ApiImplicitParam(name = "newsAbstract", value = "新闻摘要", dataType = "String", dataTypeClass = String.class),
                @ApiImplicitParam(name = "newsImg", value = "新闻图片", dataType = "String", dataTypeClass = String.class),
                @ApiImplicitParam(name = "userId", value = "用户ID", dataType = "Long", dataTypeClass = Long.class),
                @ApiImplicitParam(name = "deptId", value = "部门ID", dataType = "Long", dataTypeClass = Long.class),
                @ApiImplicitParam(name = "createBy", value = "创建者", dataType = "String", dataTypeClass = String.class),
                @ApiImplicitParam(name = "createTime", value = "创建时间", dataType = "Date", dataTypeClass = Date.class),
                @ApiImplicitParam(name = "updateBy", value = "更新者", dataType = "String", dataTypeClass = String.class),
                @ApiImplicitParam(name = "updateTime", value = "更新时间", dataType = "Date", dataTypeClass = Date.class),
                @ApiImplicitParam(name = "remark", value = "备注", dataType = "String", dataTypeClass = String.class),
    })
    public AjaxResult add(@Valid @RequestBody NewsInfo newsInfo)
    {
        return toAjax(newsInfoService.insertNewsInfo(newsInfo));
    }

    /**
     * 修改新闻信息
     */
    @PreAuthorize("@ss.hasPermi('newsInfo:newsInfo:edit')")
    @Log(title = "新闻信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改新闻信息",notes = "修改新闻信息")
    @ApiImplicitParams({
                @ApiImplicitParam(name = "newsId", value = "序号", dataType = "Long", dataTypeClass = Long.class),
                @ApiImplicitParam(name = "newsTitle", value = "新闻标题", dataType = "String", dataTypeClass = String.class),
                @ApiImplicitParam(name = "newsTime", value = "新闻发布时间", dataType = "Date", dataTypeClass = Date.class),
                @ApiImplicitParam(name = "newsContent", value = "新闻内容", dataType = "String", dataTypeClass = String.class),
                @ApiImplicitParam(name = "newsAbstract", value = "新闻摘要", dataType = "String", dataTypeClass = String.class),
                @ApiImplicitParam(name = "newsImg", value = "新闻图片", dataType = "String", dataTypeClass = String.class),
                @ApiImplicitParam(name = "userId", value = "用户ID", dataType = "Long", dataTypeClass = Long.class),
                @ApiImplicitParam(name = "deptId", value = "部门ID", dataType = "Long", dataTypeClass = Long.class),
                @ApiImplicitParam(name = "createBy", value = "创建者", dataType = "String", dataTypeClass = String.class),
                @ApiImplicitParam(name = "createTime", value = "创建时间", dataType = "Date", dataTypeClass = Date.class),
                @ApiImplicitParam(name = "updateBy", value = "更新者", dataType = "String", dataTypeClass = String.class),
                @ApiImplicitParam(name = "updateTime", value = "更新时间", dataType = "Date", dataTypeClass = Date.class),
                @ApiImplicitParam(name = "remark", value = "备注", dataType = "String", dataTypeClass = String.class),
    })
    public AjaxResult edit(@Valid @RequestBody NewsInfo newsInfo)
    {
        return toAjax(newsInfoService.updateNewsInfo(newsInfo));
    }

    /**
     * 删除新闻信息
     */
    @PreAuthorize("@ss.hasPermi('newsInfo:newsInfo:remove')")
    @Log(title = "新闻信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{newsIds}")
    @ApiOperation(value = "删除新闻信息",notes = "删除新闻信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "newsIds", value = "newsIds", dataType = "newsIds", dataTypeClass = Long.class),
    })
    public AjaxResult remove(@Valid @NotEmpty(message = "newsIds字段不能为空") @PathVariable Long[] newsIds)
    {
        return toAjax(newsInfoService.deleteNewsInfoByNewsIds(newsIds));
    }
}
